<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<!-- 引入bootstrap的css -->
<link rel="stylesheet" href="../js/bootstrap/bootstrap3/css/bootstrap.css">
<link rel="stylesheet" href="../js/bootstrap/bootstrap3/css/bootstrap-theme.css">
<!-- 引入jquery的js -->
<script type="text/javascript" src="../js/jquery.min.js"></script>
<!-- 引入bootstrap的js -->
<script type="text/javascript" src="../js/bootstrap/bootstrap3/js/bootstrap.js"></script>

<!-- 引入boostrap的表格的css、js -->
<link rel="stylesheet" href="../js/bootstrap/bootstrap-table/bootstrap-table.css">
<script type="text/javascript" src="../js/bootstrap/bootstrap-table/bootstrap-table.js"></script>
<script type="text/javascript" src="../js/bootstrap/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
<!-- 引入bootbox弹框的js -->
<script type="text/javascript" src="../js/bootstrap/bootstrap-bootbox/bootbox.js"></script>

<!-- 引入bootstrap的日期的css、js -->
<link rel="stylesheet" href="../js/bootstrap/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css">
<script type="text/javascript" src="../js/bootstrap/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
<script type="text/javascript" src="../js/bootstrap/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<!-- 引入fileinput 文件上传的 css、js -->
<link rel="stylesheet" href="../js/bootstrap/bootstrap-fileinput/css/fileinput.css">
<script type="text/javascript" src="../js/bootstrap/bootstrap-fileinput/js/fileinput.js"></script>
<script type="text/javascript" src="../js/bootstrap/bootstrap-fileinput/js/locales/zh.js"></script>

<body>
<table>
    <tr>
        <td>放映时间 ：</td>
        <td><select onchange="dataa()"  class="form-control" id="playData"></select></td>
        <td>放映影厅 ：</td>
        <td><select    class="form-control" id="hallId2" ></select></td>
        <td><button onclick="penAdd()" class="btn btn-primary glyphicon glyphicon-plus" type="button">新增</button></td>

    </tr>

</table>

<div id="table"></div>

<input type="hidden" id="dataaa"  >

</body>

<script th:inline="javascript">

    $(function(){
        var dateTime=new Date();
        $("#dataaa").val(dateTime.toLocaleDateString());
        butt();
        hallCount();
        queryPlay();

    })

    //放映时间下拉框
    function butt(){
        var dateTime=new Date();

        var str='    <option value="0">今日</option>'

        for (var i = 1; i <= 3; i++) {
            var dateTime=new Date();
            dateTime=dateTime.setDate(dateTime.getDate()+i);
            dateTime=new Date(dateTime);
            var yue = dateTime.getMonth()+1+'月'+dateTime.getDate()+'日';
             str+='    <option   value="'+i+'">'+yue+'</option>'
        }
        $("#playData").html(str)

    }

    //放映时间
    function dataa(){

      var num=  $("#playData").val()
          num=parseInt(num);
        var dateTime=new Date();
        dateTime=dateTime.setDate(dateTime.getDate()+num);
        dateTime=new Date(dateTime).toLocaleString();
         $("#dataaa").val(dateTime);
        queryPlay();
    }

    //查询影厅
    function hallCount(){
        $.ajax({
            url:"../plan/hallCount",
            type:"get",
            data:{id: [[${session.user.cinemaId}]]},
            async:false,
            success:function(data){
                var str='    <option value="0">全部影厅</option>'
                for (var i = 0 ;i < data.length; i++) {

                    str+=' <option   value="'+data[i].hallId+'">'+data[i].hallname+'</option>';
                }
                $("#hallId2").html(str)
                $("#playData2").html(str)

            }
        })
    }
    function hallCount2(){
        $.ajax({
            url:"../plan/hallCount",
            type:"get",
            data:{id: [[${session.user.cinemaId}]]},
            async:false,
            success:function(data){
                var str='    <option value="0">请选择</option>'
                for (var i = 0 ;i < data.length; i++) {

                    str+=' <option   value="'+data[i].hallId+'">'+data[i].hallname+'</option>';
                }
                $("#playData2").html(str)

            }
        })
    }

    //查询计划
    function queryPlay(){

        var  date=  $("#dataaa").val()
        var  hallId=  $("#hallId2").val()
        $.ajax({
            url:"../plan/queryPlan",
            type:"get",
            data:{dateTime: date,id:[[${session.user.cinemaId}]],hallId:hallId},
            async:false,
            success:function(data){

                var str='<table class="table table-hover  table-striped" >';

                str+=' <tr class="warning">' +
                        '<td>影片名称</td>' +
                        '<td>放映日期</td>' +
                        '<td>放映时间</td>' +
                        '<td>结束时间</td>' +
                        '<td>影厅</td>' +
                        '<td>语言</td>' +
                        '<td>票价</td>' +
                    '</tr>';

                for (var i = 0; i <data.length ; i++) {
                    str+=' <tr class="warning">' +
                            '<td>'+data[i].movieName+'</td>' +
                            '<td>'+data[i].date+'</td>' +
                            '<td>'+data[i].playStartTime+'</td>' +
                            '<td>'+data[i].playEndTime+'</td>' +
                            '<td>'+data[i].hallname+'</td>' +
                            '<td>'+data[i].movieLanguage+'</td>' +
                            '<td>'+data[i].moviePrice+'</td>' +
                        '</tr>';
                }

                str+='</table>';
                $("#table").html(str);



            }
        })
    }

    //合并页面
    var res;
    function createAddContent(url){
        $.ajax({
            url:url,
            async:false,//同步
            success:function(data){
                res = data;
            }
        });
        return res;
    }
    function penAdd(){
        bootbox.dialog({
            title:'新增放映计划',
            message: createAddContent("../planPage/addplay"),//合并页面
            closeButton: true,
            buttons : {
                "success" : {
                    "label" : "<i class='icon-ok'></i> 保存",
                    "className" : "btn-sm btn-success",
                    "callback" : function() {//回调函数
                        //提交表单
                        $.ajax({
                            url:"../plan/addplay",
                            type:'post',
                            data:$("#addForm").serialize(),//表单序列化
                            success:function(data){
                               alert(data)
                                queryPlay();

                            }
                        });
                    }
                },
                "cancel" : {
                    "label" : "<i class='icon-info'></i> 取消",
                    "className" : "btn-sm btn-danger"
                }
            }

        })
        hallCount2();
        queryMovie();
    }


    //电影下拉框
    function queryMovie(){
        $.ajax({
            url:"../sec/findPictureAll",
            type:"get",
            data:{page:1,rows:100},
            async:false,
            success:function(data){

                var str='    <option value="0">请选择</option>'
                for (var i = 0 ;i < data.rows.length; i++) {

                    str+=' <option   value="'+data.rows[i].movieId+'">'+data.rows[i].movieName+'</option>';
                }
                $("#movieid2").html(str)

            }
        })
    }






</script>




</html>